package com.gxa.modules.aspect;

import com.gxa.common.utils.IpUtils;
import com.gxa.modules.mapper.LogMapper;
import com.gxa.modules.pojo.Sys_Action_Log;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;


import javax.servlet.http.HttpServletRequest;
import java.util.Date;

@Service
//    操作日志切面类
@Aspect
@Component
public class SystemLogAspect {

    @Autowired(required = false)
    private  LogMapper logMapper;
//    private Object request;
//    private Logger logger = LoggerFactory.getLogger(SystemLogAspect.class);

@Before("execution(* com.gxa.modules.service.impl.CommodityServiceImpl.queryCommodityMap(..))")
    public static void beforePrintLog(){
    System.out.println("==调用前打印日志=="+new Date().toLocaleString());
}


@After("execution(* com.gxa.modules.service.impl.CommodityServiceImpl.queryCommodityMap(..))")
public  void afterPrintCommodityLog(){
//    String Ip = IpUtils.getIpAddr((HttpServletRequest) request);
    Sys_Action_Log sys_action_log = new Sys_Action_Log();
    sys_action_log.setName("商品列表查询");
    sys_action_log.setType(1);
    sys_action_log.setIpaddr("接收登录IP"+"192.336.2.221");
    sys_action_log.setClazz("com.gxa.modules.service.impl.CommodityServiceImpl.queryCommodityMap");

    sys_action_log.setMethod("commodity");
    sys_action_log.setMadel("暂无数据");
    sys_action_log.setRecord_id(0);
    sys_action_log.setMessage("查询成功！暂无文本数据");
    sys_action_log.setCreate_date(new Date());
//    System.out.println(sys_action_log.getCreate_Date());
    sys_action_log.setOper_name("admin");
    logMapper.insertLogMap(sys_action_log);
    System.out.println("==调用后打印日志=="+new Date().toLocaleString());
}

    @After("execution(* com.gxa.modules.service.impl.OrdersServiceImpl.queryOrdersList(..))")
    public  void afterPrintOrdersLog(){
        Sys_Action_Log sys_action_log = new Sys_Action_Log();
        sys_action_log.setName("订单列表查询");
        sys_action_log.setType(1);
        sys_action_log.setIpaddr("192.19.223.33");
        sys_action_log.setClazz("com.gxa.modules.service.impl.OrdersServiceImpl.queryOrdersList");
        sys_action_log.setMethod("查询");
        sys_action_log.setMethod("Orders");
        sys_action_log.setRecord_id(0);
        sys_action_log.setMessage("查询成功！暂无文本数据");
        sys_action_log.setCreate_date(new Date());

        sys_action_log.setOper_name("admin");
        logMapper.insertLogMap(sys_action_log);
        System.out.println("==调用后打印日志=="+new Date().toLocaleString());
    }
//    @Before("execution(* com.gxa.modules.service.impl.CommodityServiceImpl.queryCommodityMap(..))")
//    public static void beforePrintLog(){
//        System.out.println("==调用前打印日志=="+new Date().toLocaleString());
//    }

}
